home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / StringCvt.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  2.8 KB  |  70 lines  |  [TEXT/R*ch]

  1. (* StringCvt -- SML Standard Library *)
  2.  
  3. datatype radix = BIN | OCT | DEC | HEX;
  4.  
  5. datatype realfmt = 
  6.     SCI of int option   (* scientific,  arg = # dec. digits, dflt=6 *)
  7.   | FIX of int option   (* fixed-point, arg = # dec. digits, dflt=6 *)
  8.   | GEN of int option   (* auto choice of the above,                *)
  9.                         (* arg = # significant digits, dflt=12      *)
  10.  
  11. type 'charsrc accessor = {getc : 'charsrc -> (char * 'charsrc) option}
  12. type ('charsrc, 'result) converter = 
  13.      'charsrc accessor -> 'charsrc -> ('result * 'charsrc) option
  14.  
  15. val skipWS     : 'charsrc accessor -> 'charsrc -> 'charsrc
  16. val scanString : (int, 'result) converter -> string -> 'result option
  17.  
  18. val toChar     : string -> char option          (* ML escape sequences *)
  19. val toString   : string -> string option        (* ML escape sequences *)
  20.  
  21. val fromChar   : char -> string                 (* ML escape sequences *)
  22. val fromString : string -> string               (* ML escape sequences *)
  23.  
  24. val padLeft    : char -> int -> string -> string
  25. val padRight   : char -> int -> string -> string
  26.  
  27.  
  28. (* These datatypes and functions are used for scanning strings into
  29.    data values, and for formatting data values to strings.  
  30.  
  31.    A character source charsrc can be used to obtain a sequence of
  32.    characters; it can be thought of as a functional character stream.
  33.  
  34.    A 'charsrc accessor getc obtains characters from a 'charsrc, one at
  35.    a time.
  36.  
  37.    A character source scanner takes a 'charsrc accessor getc as
  38.    argument and uses it to scan some simple data value from the
  39.    character source.
  40.  
  41.    [skipWS getc charsrc] returns a character source which is charsrc
  42.    less any leading whitespace.
  43.  
  44.    [scanString scan s] turns the string s into a character source and
  45.    applies the scanner `scan' to that source.
  46.  
  47.    [toChar s] scans the string s for an ML character or escape
  48.    sequence into the character it represents.  Does not skip leading
  49.    whitespace.  For instance, toChar "\\065" equals #"A"
  50.  
  51.    [fromChar c] returns a string consisting of the character c, or an
  52.    ML escape sequence corresponding to c.  For instance, 
  53.         fromChar #"A" equals "\\065"
  54.  
  55.    [toString s] scans the string s as an ML source program string,
  56.    converting escape sequences into the appropriate characters.  Does
  57.    not skip leading whitespace.
  58.  
  59.    [fromString s] returns a string corresponding to s, with
  60.    non-printable characters replaced by escape sequences.
  61.  
  62.    [padLeft c n s] returns the string s if size s >= n, otherwise pads
  63.    s with (n - size s) copies of the character c on the left.  
  64.    In other words, right-justifies s in a field n characters wide.
  65.  
  66.    [padRight c n s] returns the string s if size s >= n, otherwise pads
  67.    s with (n - size s) copies of the character c on the right.
  68.    In other words, left-justifies s in a field n characters wide.
  69. *)
  70.